﻿package mortal.game.view.task.drama.operations
{
    import Message.DB.Tables.*;
    import com.gengine.global.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.common.swfPlayer.*;
    import mortal.game.manager.*;

    public class TaskDramaMovie extends Object implements ITaskDramaStepCommand
    {
        private var _callback:Function;
        private var _player:FLVPlayer;
        private var _mWidth:int;
        private var _mHeight:int;
        private var _dramaData:TTaskDrama;
        private var _sp:GSprite;

        public function TaskDramaMovie()
        {
            return;
        }// end function

        public function call(param1:TTaskDrama, param2:Function = null) : void
        {
            this._callback = param2;
            this._dramaData = param1;
            if (this._sp == null)
            {
                this._sp = UICompomentPool.getUICompoment(GSprite);
                DisplayUtil.drawFullScreenMask(this._sp, 0, 1);
                LayerManager.dramaMovieLayer.addChild(this._sp);
            }
            if (this._player != null)
            {
                DisplayUtil.removeMe(this._player);
                this._player.dispose(false);
                this._player = null;
            }
            this._player = new FLVPlayer();
            this._player.play(PathConst.mainPath + "assets/movie/" + param1.talkText + "?v=" + ParamsConst.instance.flashVersion, this.moviePlayEnd);
            this._player.setSize(param1.valueOne, param1.valueTwo);
            this._player.x = (Global.stage.stageWidth - param1.valueOne) / 2;
            this._player.y = (Global.stage.stageHeight - param1.valueTwo) / 2;
            LayerManager.dramaMovieLayer.addChild(this._player);
            return;
        }// end function

        public function onStageResize() : void
        {
            if (this._player != null && this._dramaData != null)
            {
                this._player.x = (Global.stage.stageWidth - this._dramaData.valueOne) / 2;
                this._player.y = (Global.stage.stageHeight - this._dramaData.valueTwo) / 2;
            }
            return;
        }// end function

        private function moviePlayEnd(param1:FLVPlayer) : void
        {
            this.callEnd();
            return;
        }// end function

        public function cancel(param1:TTaskDrama, param2:Function = null) : void
        {
            this._callback = param2;
            this.callEnd();
            return;
        }// end function

        private function callEnd() : void
        {
            if (this._player != null)
            {
                DisplayUtil.removeMe(this._player);
                this._player.dispose(false);
                this._player = null;
            }
            if (this._sp != null)
            {
                this._sp.dispose(true);
                this._sp = null;
            }
            if (this._callback != null)
            {
                this._callback.call();
                this._callback = null;
            }
            return;
        }// end function

    }
}
